package com.b2b2c.store.single.logic;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.servlet.http.HttpServletRequest;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import com.b2b2c.store.single.entity.Freights;
import com.b2b2c.store.single.mapper.FreightsMapper;
import com.b2b2c.store.single.service.IFreightsService;

/**
   *     品牌列表
 * @author Administrator
 */
public class FreightLogic extends AbstractLogic<Freights, Object> implements IFreightsService<Freights>
{

	public FreightLogic(HttpServletRequest req) {
		super(req);
		// TODO Auto-generated constructor stub
	}

	@Override
	public Map<String, Map<String, String>> getValidateRule() {
		// TODO Auto-generated method stub
		
		return null;
	}
	
	/**
	 * 
	 * @return
	 */
	public List<Freights> getFreightsList(RedisTemplate<String, List<Freights>> redisTemplate) {
		
		
		ValueOperations<String, List<Freights>> valueOption =  redisTemplate.opsForValue();
		
		String key =  "freights_cache_me1122";
		
		List<Freights> list = valueOption.get(key);
		
		if(list != null) {
			return list;
		}
		
		List<Freights> freightList = this.getSqlTemp().getMapper(FreightsMapper.class).getFreightByStoreId((Integer)this.getReq().getSession().getAttribute("store_id"));
		
		this.getSqlTemp().clearCache();
		
		if (freightList == null) {
			return freightList;
		}
		
		valueOption.set(key, freightList, 60, TimeUnit.SECONDS);
		
		return freightList;
	}

	

}
